/*
 * @name: 添加自营商品弹窗
 * @Author: along
 * @Date: 2020-06-10
 */
<template>
    <el-dialog
        :visible.sync="dialogShop"
        :close-on-click-modal="false"
        width="80%"
    >
        <div class="container zdLuckAddShop">
            <!-- header -->
            <div class="header-nav">
                <div class="header-left">
                    <div class="header-new-box">
                        <p class="header-new-box-title">商品名称:</p>
                        <el-input
                            v-model="head.shop_name"
                            placeholder="请输入商品名称"
                            size="small"
                            clearable
                            suffix-icon="el-icon-search"
                            @change="getTableData(1)"
                            @keyup.native.enter="getTableData(1)"
                        />
                    </div>
                    <div class="header-new-box">
                        <p class="header-new-box-title">店铺搜索:</p>
                        <el-input
                            v-model="head.shop_title"
                            placeholder="请输入店铺名称"
                            size="small"
                            clearable
                            suffix-icon="el-icon-search"
                            @change="getTableData(1)"
                            @keyup.native.enter="getTableData(1)"
                        />
                    </div>
                    <div class="header-new-box">
                        <p class="header-new-box-title">公司名称:</p>
                        <el-input
                            v-model="head.company_name"
                            placeholder="请输入公司名称"
                            size="small"
                            clearable
                            suffix-icon="el-icon-search"
                            @change="getTableData(1)"
                            @keyup.native.enter="getTableData(1)"
                        />
                    </div>
                </div>
                <div class="header-right">
                    <div class="header-new-box">
                        <el-button
                            type="primary"
                            size="small"
                            @click="getTableData(1)"
                        >
                            搜索
                        </el-button>
                    </div>
                </div>
            </div>
            <!-- /header -->

            <!-- table -->
            <el-table
                :data="tableData"
                height="100%"
                style="width: 100%;"
                border
                ref="zdLuckAddShop"
            >
                <el-table-column
                    prop="goods_title"
                    label="商品名称"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                >
                    <template slot-scope="scope">
                        <div class="zd-goods">
                            <img
                                v-if="scope.row.goods_cover"
                                :src="scope.row.goods_cover"
                                alt="加载失败"
                                class="zd-goods-cover"
                                @click="fnShowPreview(scope.row.goods_cover)"
                            >
                            <p class="zd-goods-title">
                                {{ scope.row.goods_title }}
                            </p>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column
                    prop="goods_price"
                    label="商品售价"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                />
                <el-table-column
                    prop="goods_price_origin"
                    label="商品原价"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                />
                <el-table-column
                    prop="goods_stock"
                    label="商品总库存"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                />
                <el-table-column
                    label="操作"
                    align="center"
                >
                    <template slot-scope="scope">
                        <el-button
                            type="primary"
                            class="curse-add"
                            @click="fnSelectShop(scope.row)"
                            size="small"
                        >
                            确定
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!-- /table -->

            <!-- foot -->
            <div class="zd-foot">
                <el-button
                    type="info"
                    size="small"
                    style="width:100px"
                    @click="()=>{
                        dialogShop = false;
                    }"
                >
                    关闭
                </el-button>
            </div>
        </div>
        <!-- 图片预览 -->
        <img-preview ref="preview" />
    </el-dialog>

</template>

<script>
import { back } from '@/mixin/back';
import imgPreview from '@/components/common/img-preview';
export default {
    name: 'ZDADDSHOP',
    mixins: [back],
    components: {
        imgPreview
    },
    data () {
        return {
            head: {
                shop_name: '',
                shop_title: '',
                company_name: ''
            },
            tableData: [],
            dialogShop: false
        };
    },
    filters: {},
    computed: {},
    watch: {},
    mounted () {
        this.tableData = [];
    },
    methods: {
        /**
         * 打开弹窗
         */
        showDialog () {
            this.dialogShop = true;
        },

        /**
         * 获取表格数据
         */
        getTableData () {
            this.$post('/student/shop_lottery%5Csearch_goods', {
                goods_title: this.head.shop_name,
                shop_title: this.head.shop_title,
                company_title: this.head.company_name
            }, resp => {
                if (resp.code == 1) {
                    this.tableData = resp.data.list;
                }
            });
        },

        /**
         * 选择/取消选择
         */
        fnSelectShop (row, type) {
            this.$emit('changeData', row);
            this.dialogShop = false;
        },

        /**
         * 查看图片
         * @param   {String}    images      //单图预览
         * @param   {Array}     images      //多图预览
         */
        fnShowPreview(images) {
            if(images && Object.prototype.toString.call(images) == '[object String]') {
                this.$refs.preview.show([
                    images
                ]);
            } else if (images && Object.prototype.toString.call(images) == '[object Array]') {
                this.$refs.preview.show(images);
            } else {
                this.$message({
                    type: 'warning',
                    message: '图片类型错误'
                });
            }
        },

        /**
         * 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        }
    }
};
</script>

<style lang="less" scoped>
    .container {
        background-color: #fff;
        padding: 10px 15px 5px 15px;
        display: flex;
        flex-direction: column;
        position: relative;
        width: 100%;
        .header-nav {
            position: relative;
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            justify-content: space-between;
            .header-left, .header-right {
                display: flex;
                align-items: center;
                flex-wrap: wrap;
            }
            .header-new-box {
                display: flex;
                margin-right: 15px;
                align-items: center;
                color: #606266;
                margin-bottom: 10px;
                white-space: nowrap;
                &-title {
                    margin-right: 2px;
                    white-space: nowrap;
                }
            }
        }
        /* 表单 */
        .scope-price {
            width: 50px;
            height: 50px;
        }
        /* 字体高亮 */
        .cursor-font {
            color: rgb(64, 158, 255);
            cursor: pointer;
        }
        /* 分页 */
        .pagination-wrapper {
            padding-top: 10px;
            padding-bottom: 10px;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
    }
    /* 排序 */
    .sort-wrap {
        display: flex;
        align-items: center;
        cursor: pointer;
        .sort-spliter {
            width: 1px;
            height: 12px;
            background: rgba(235, 235, 235, 1);
            margin: 0 10px;
            }
            .btn-sort {
            font-size: 14px;
            line-height: 1;
            color: #ccc;
            &:hover {
                color: #20a0ff;
            }
        }
    }
    .el-button-left {
        margin-left: 40px;
    }
    .el-button-right {
        margin-right: 10px;
    }
    .zd-goods {
        display: flex;
        align-content: center;
        height: 40px;
        &-cover {
            width: 40px;
            height: 40px;
        }
        &-title {
            font-size: 14px;
            color: #333;
            margin-left: 8px;
            white-space: nowrap;
            height: 40px;
            line-height: 40px;
        }
    }
    .zd-foot {
        width: 100%;
        height: 32px;
        display: flex;
        justify-content: center;
        margin-top: 25px;
    }
</style>
<style lang="less">
    .zdLuckAddShop{
        .el-table__body-wrapper .el-table__body .el-table__row td {
            border-right: none;
        }
        .el-table__header-wrapper .el-table__header .has-gutter tr th {
            border-right: none;
        }
        .el-table .el-table_1_column_6  .cell {
            position: relative;
        }
        .el-range-editor--small .el-range-separator{
            padding: 0 1px !important;
        }
        .el-table__body-wrapper {
            height: auto !important;
            max-height: 400px !important;
        }
    }
</style>